/*
 * TransitionMapping.java
 *
 * Stateroom - Java framework library for finite state machines
 * Copyright (C) 2009 by Matthew Werny
 * All Rights Reserved
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */
package net.iceflow.stateroom;

import net.iceflow.stateroom.interfaces.Condition;
import net.iceflow.stateroom.interfaces.Model;
import net.iceflow.stateroom.interfaces.State;

/**
 * Provides a structured mapping between a single target state and an instance of the Condition implementation.
 * <p>
 * The condition indicates the instantaneous truth as to whether the target state should become the new state of the machine for
 * the next evaluation of the machine.
 * </p>
 * @param <M> Type used to represent the machine model
 */
class TransitionMapping<M extends Model> {

   /** Condition used to determine if this state transition should be taken. */
   private final Condition<M> _condition;

   /** Target state to transition to, if the condition exists, such that a transition should take place. */
   private final State<M> _targetState;

   /**
    * Constructs a new TransitionMapping.
    * @param condition Condition instance used to determine if this state transition should be taken
    * @param targetState target state to which to transition, if condition exists
    */
   public TransitionMapping(final Condition<M> condition, final State<M> targetState) {
      // Validate that neither of the arguments are null
      Utility.validateNotNull(condition, "condition may not be null");
      Utility.validateNotNull(targetState, "targetState may not be null");

      // Set the final object instance for the condition field
      this._condition = condition;

      // Set the final object instance for the target state field
      this._targetState = targetState;
   }

   /**
    * Getter for the condition field.
    * @return Condition instance used to determine if this state transition should be followed
    */
   public Condition<M> getCondition() {
      // Return the condition instance contained within this mapping
      return this._condition;
   }

   /**
    * Getter for the targetState field.
    * @return target state that should be transitioned to, if the condition is sufficient for the change
    */
   public State<M> getTargetState() {
      // Return the state that this transition targets
      return this._targetState;
   }
}
